from apps import dbUtil


def get_trailer_command(trailer_ID):
    db = dbUtil.getDbConnection()
    # 使用cursor()方法创建一个游标对象
    cursor = db.cursor()

    # 使用execute()方法执行SQL语句
    cursor.execute('SELECT command_details FROM command WHERE trailer_ID = "' + str(trailer_ID) + '" order by command_ID DESC limit 1;')
    print('SELECT command_details FROM command WHERE trailer_ID = "' + str(trailer_ID) + '" order by command_ID DESC limit 1;')

    # 使用fetall()获取全部数据
    data = cursor.fetchall()


    # 关闭游标和数据库的连接
    cursor.close()
    db.close()
    print("len = ", len(data))
    if len(data) == 0:
        return "no command"
    else:
        return data[0][0]

if __name__ == '__main__':
    get_trailer_command("trailer003")